package com.example.controller;

import com.example.common.Result;
import com.example.entity.City;
import com.example.service.CityService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * 城市信息前端请求的端口
 */
@RestController
@RequestMapping("/city")
public class CityController {

    @Resource
    private CityService cityService;
/*
* 新增
*
*
* */

    @PostMapping("/add")
    public Result add(@RequestBody  City city){
        cityService.add(city);

     return Result.success();
    }

    /*
    * 更新
    * */
    @PutMapping("/update")
    public Result update(@RequestBody City city) {
        cityService.updateById(city);
        return Result.success();
    }

    /*
     * 删除
     * */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        cityService.deleteById(id);
        return Result.success();
    }

/**
 *
 * 分页查询
 */
@GetMapping("/selectPage")
public Result selectPage(City city,
                         @RequestParam(defaultValue = "1") Integer pageNum,
                         @RequestParam(defaultValue = "5") Integer pageSize) {
    PageInfo<City> pageInfo = cityService.selectPage(city, pageNum, pageSize);
    return Result.success(pageInfo);
}
/**
 *
 * 查询所有
 */
@GetMapping("/selectAll")
    public Result selectAll(){
        List<City> list=cityService.selectAll();
        return Result.success(list);

    }


}
